<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  
  <title>4-机器人模型 URDF 及 XACRO | ChenBlue | 飞雪连天射白鹿 笑书神侠倚碧鸳</title>

  
  <meta name="author" content="ChenBlue">
  

  
  <meta name="description" content="学习笔记">
  

  
  
  <meta name="keywords" content="ROS">
  

  <meta id="viewport" name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">

  <meta property="og:title" content="4-机器人模型 URDF 及 XACRO"/>

  <meta property="og:site_name" content="ChenBlue"/>

  
  <meta property="og:image" content="/blog/favicon.ico"/>
  

  <link href="/blog/favicon.ico" rel="icon">
  <link rel="alternate" href="/blog/atom.xml" title="ChenBlue" type="application/atom+xml">
  <link rel="stylesheet" href="/blog/css/style.css" media="screen" type="text/css">
<meta name="generator" content="Hexo 5.4.0"></head>


<body>
<div class="blog">
  <div class="content">

    <header>
  <div class="site-branding">
    <h1 class="site-title">
      <a href="/blog/">ChenBlue</a>
    </h1>
    <p class="site-description">飞雪连天射白鹿 笑书神侠倚碧鸳</p>
  </div>
  <nav class="site-navigation">
    <ul>
      
    </ul>
  </nav>
</header>

    <main class="site-main posts-loop">
    <article>

  
    
    <h3 class="article-title"><span>4-机器人模型 URDF 及 XACRO</span></h3>
    
  

  <div class="article-top-meta">
    <span class="posted-on">
      <a href="/blog/2021/04/12/4-机器人模型 URDF 及 XACRO/" rel="bookmark">
        <time class="entry-date published" datetime="2021-04-12T12:39:03.000Z">
          2021-04-12
        </time>
      </a>
    </span>
  </div>


  

  <div class="article-content">
    <div class="entry">
      
        <h1 id="URDF-机器人模型"><a href="#URDF-机器人模型" class="headerlink" title="URDF 机器人模型"></a>URDF 机器人模型</h1><h2 id="URDF-模型的两个重要属性"><a href="#URDF-模型的两个重要属性" class="headerlink" title="URDF 模型的两个重要属性"></a>URDF 模型的两个重要属性</h2><h3 id="link"><a href="#link" class="headerlink" title="link"></a>link</h3><blockquote>
<p>描述机器人某个刚体部分的外观和物理属性;</p>
<p>描述连杆尺寸(size)、颜色(color)，形状(shape) 惯性矩阵(inertial matrix)，碰撞参数(collision properties)等。</p>
<p>每个Link会成为一个坐标系</p>
</blockquote>
<pre class="language-html" data-language="html"><code class="language-html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>link</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>link 4<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>visual</span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>geometry</span><span class="token punctuation">></span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>mesh</span> <span class="token attr-name">filename</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>link 4.stl<span class="token punctuation">"</span></span><span class="token punctuation">/></span></span>
        &lt;/ geometry>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>origin</span> <span class="token attr-name">xyz</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>0 0 0<span class="token punctuation">"</span></span> <span class="token attr-name">rpy</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>0 0 0<span class="token punctuation">"</span></span><span class="token punctuation">/></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>visual</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>collision</span><span class="token punctuation">></span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>geometry</span><span class="token punctuation">></span></span>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>cylinder</span> <span class="token attr-name">length</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>0.5<span class="token punctuation">"</span></span> <span class="token attr-name">radius</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>0.1<span class="token punctuation">"</span></span><span class="token punctuation">/></span></span>
        &lt;/ geometry>
            <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>origin</span> <span class="token attr-name">xyz</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>0 0 -o.05<span class="token punctuation">"</span></span><span class="token attr-name">rpy</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>0 0 0<span class="token punctuation">"</span></span><span class="token punctuation">/></span></span>
    &lt;/ collision>
&lt;/ link></code></pre>

<h3 id="joint"><a href="#joint" class="headerlink" title="joint"></a>joint</h3><blockquote>
<p>描述两个link之间的关系，分为六种类型;</p>
<p>包括关节运动的位置和速度限制;</p>
<p>描述机器人关节的运动学和动力学属性。</p>
</blockquote>
<table>
<thead>
<tr>
<th align="center">关节类型</th>
<th align="center">描述</th>
</tr>
</thead>
<tbody><tr>
<td align="center">continuous</td>
<td align="center">旋转关节，可以围绕单轴无限旋转</td>
</tr>
<tr>
<td align="center">revolute</td>
<td align="center">旋转关节，类似于continuous 但是有旋转的角度极限</td>
</tr>
<tr>
<td align="center">prismatic</td>
<td align="center">滑动关节，沿某一轴线性移动的关节，带有位置极限</td>
</tr>
<tr>
<td align="center">planar</td>
<td align="center">平面关节，允许在平面正交方向上平移或者旋转</td>
</tr>
<tr>
<td align="center">floating</td>
<td align="center">浮动关节，允许进行平移、旋转运动</td>
</tr>
<tr>
<td align="center">fixed</td>
<td align="center">固定关节，不允许运动的特殊关节</td>
</tr>
</tbody></table>
<pre class="language-none"><code class="language-none">&lt;joint name&#x3D;&quot;joint_2&quot; type&#x3D;&quot;revolute &quot;&gt;
    &lt;parent link&#x3D; &quot;link_1&quot;&#x2F;&gt;
    &lt;child link&#x3D; &quot;link_2&quot;&#x2F;&gt;
    &lt;origin xyz&#x3D;&quot;0.2 0.2 0&quot; rpy&#x3D;&quot;o o 0&quot;&#x2F;&gt;
    &lt;axis xyz&#x3D;&quot;O 0 1&quot;&#x2F;&gt;
    &lt;limit lower&#x3D;&quot;-3.14&quot; upper&#x3D;&quot;3.14&quot; velocity&#x3D;&quot;1.0&quot;&#x2F;&gt;
&lt;&#x2F;joint&gt;</code></pre>

<p><strong>创建功能包</strong></p>
<pre class="language-none"><code class="language-none">catkin_create_pkg  mbot_description urdf xacro</code></pre>
<p><strong>安装rviz里的gui</strong></p>
<pre class="language-none"><code class="language-none">sudo apt-get install ros-melodic-joint-state-publisher-gui </code></pre>
<p><strong>检查 URDF 模型的整体结构</strong></p>
<pre class="language-none"><code class="language-none">urdf_to_graphiz mbot_base.urdf</code></pre>

<h1 id="xacro"><a href="#xacro" class="headerlink" title="xacro"></a>xacro</h1><p>xacro 相比于 urdf 的优点</p>
<blockquote>
<p>精简模型代码</p>
</blockquote>
<ul>
<li>创建宏定义</li>
<li>文件包含</li>
</ul>
<blockquote>
<p>提供可编程接口</p>
</blockquote>
<ul>
<li>常量</li>
<li>变量</li>
<li>数学计算</li>
<li>条件语句</li>
</ul>
<p><strong>常量定义</strong></p>
<pre class="language-none"><code class="language-none">&lt;xacro:property name&#x3D;&quot;M_PI&quot; value&#x3D;&quot;3.14159&quot;&#x2F;&gt;</code></pre>
<p><strong>常量使用</strong></p>
<pre class="language-none"><code class="language-none">&lt;origin xyz&#x3D;&quot;o0o&quot; rpy&#x3D;&quot;$&#123;M_PI&#x2F;2&#125;0 0&quot;&#x2F;&gt;</code></pre>

<p><strong>数学计算</strong></p>
<pre class="language-none"><code class="language-none">&lt;origin xyz&#x3D;&quot;0 $&#123;(motor_length+wheel_length)&#x2F;2&#125; o&quot; rpy&#x3D;&quot;o 0 0&quot;&#x2F;&gt;</code></pre>

<p><strong>宏定义</strong></p>
<pre class="language-none"><code class="language-none">&lt;xacro:macro name&#x3D;&quot;name&quot; params&#x3D;&quot;AB C&quot;&gt;
···
&lt;&#x2F;xacro:macro&gt;</code></pre>

<p><strong>宏调用</strong></p>
<pre class="language-none"><code class="language-none">&lt;name A&#x3D; &quot;A_value&quot; B&#x3D;&quot;B_value&quot; C&#x3D; &quot;C_value&quot;</code></pre>
<p><strong>文件包含</strong></p>
<pre class="language-none"><code class="language-none">&lt;xacro:include filename&#x3D;&quot;$(find mbot description)&#x2F;urdf&#x2F;mbot base gazebo.xacro&quot;&#x2F;&gt;</code></pre>
      
    </div>

  </div>

  <div class="article-footer">
    <div class="article-meta pull-left">

    
      

    <span class="post-categories">
      <i class="icon-categories"></i>
        <a href="/blog/categories/ROS-学习笔记/">ROS 学习笔记</a>
    </span>
    

    
    

    <span class="post-tags">
      <i class="icon-tags"></i>
        <a href="/blog/tags/ROS/">ROS</a>
    </span>
    

    </div>

    
  </div>
</article>

  









    </main>

    <footer class="site-footer">
  <p class="site-info">
    Proudly powered by <a href="https://hexo.io/" target="_blank">Hexo</a> and
    Theme by <a href="https://github.com/CodeDaraW/Hacker" target="_blank">Hacker</a>
    </br>
    
    &copy; 2023 ChenBlue
    
  </p>
</footer>
    
    
  </div>
</div>
</body>
</html>